import {ref, computed} from 'vue'
import {defineStore} from 'pinia'

export const usePathStore = defineStore('path', () => {
    const path = ref('/index')
    const Tabs = ref([
        {
            title: '主页',
            name: '/index',
            content: '/index',
        },
    ])
    const getPath = computed(() => path.value)
    const getTabs = computed(() => Tabs.value)

    const setPath = (key) => {
        path.value = key
    }

    const addTab = (item) => {
        Tabs.value.push(item)
    }
    const setTab = (item) => {
        Tabs.value = item
    }

    function $reset() {
        path.value = '/index'
        Tabs.value = [
            {
                title: '主页',
                name: '/index',
                content: '/index',
            },
        ]
    }

    return {path, Tabs, getPath, getTabs, setPath, setTab, addTab, $reset}
}, {
    persist: {
        key: 'pathStore', //存储名称
        storage: sessionStorage, // 存储方式
    }
})
